


#include "stdafx.h"
#include "MsgBuildlerForGate.h"
#include "MsgInRawStream.h"


bool
MsgBuilderForGate::onEncodeMsg(IMsgRoute* pMsgRoute, IMsg* pMsg, MsgOStream& stream)
{
	if (pMsg!=NULL)
	{
		stream<<pMsg->getMsgCate()<<pMsg->getMsgID();

		return pMsg->encode(stream);
	}
	else
	{
		return false;
	}
}


bool
MsgBuilderForGate::onDecodeMsg(IMsgRoute*& pMsgRoute, IMsg*& pMsg, MsgIStream& stream)
{
	int nMC = 0, nMID = 0;
	stream>>nMC>>nMID;

	pMsg = createMsg(nMID, nMID);
	if (pMsg!=NULL)
	{
		return pMsg->decode(stream);
	}
	else
	{
		return false;
	}
}

IMsg*
MsgBuilderForGate::createMsg(int nMsgCate, int nMsgID)
{
	return new MsgInRawStream;
}

